using System;
using System.Collections.Generic;
using System.Linq;
using BingGeocoder;
using System.Web;

    public class GeoCoder
    {
        public static BingGeocoderResult GeoCodeAddress(string address)
        {
            string APIKey = "";
            if (APIKey != "") { 
                var result = (BingGeocoderResult)HttpContext.Current.Cache.Get("GEO:" + address);

                if(result == null){
                    var geocoder = new BingGeocoderClient(APIKey);
                    result = geocoder.Geocode(address + " Sweden");
                    HttpContext.Current.Cache.Insert("GEO:" + address, result, null, DateTime.MaxValue,TimeSpan.FromDays(300));
                }
                
                return result;
            }
            else{
                return null;
            }
        }
    }
